import { CallHandler, ExecutionContext, Injectable, Logger, NestInterceptor } from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

/**
 * 全局相应拦截器
 */
@Injectable()
export class ResponseInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    // const ctx = context.switchToHttp();
    // const request: Request = ctx.getRequest<Request>();
    Logger.log('----------全局响应拦截器')
    return next.handle().pipe(
      map(data => {
        Logger.warn(data)
        // data.timestamp = Date.now()
        return data;
      })
    );
  }
}
